home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SIGNAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  841 b   |  39 lines

  1. /* signal.c --- BIBLE pp. 95-97 */
  2. #include <stdio.h>
  3. #include <signal.h>
  4. void ctrlc_handler(int);
  5. int back_again = 0;
  6. main()
  7. {
  8.                 /* Take over the Control-C interrupt */
  9.     if(signal(SIGINT, ctrlc_handler) == SIG_ERR)
  10.     {
  11.         perror("signal failed");
  12.         exit(0);
  13.     }
  14.     printf("Installed SIGINT signal handler\n");
  15.     printf("Hit Control-C to exit:");
  16.     while(1)
  17.     {
  18.         kbhit();
  19.         if(back_again != 0)
  20.         {
  21.             back_again = 0;
  22.             printf("\nHit Control-C to exit:");
  23.         }
  24.     }
  25. }
  26.                 /* --------------------------------- */
  27. void ctrlc_handler(int sig)
  28. {
  29.     int c;
  30.             /* First arrange to ignore further SIGINT */
  31.     signal(SIGINT, SIG_IGN);
  32.     printf("\nInterrupted.  Quit?");
  33.     c = getche();
  34.     if(c == 'y' || c == 'Y')
  35.         exit(0);
  36.             /* Reenable interrupt handler -- and return */
  37.     back_again = 1;
  38.     signal(SIGINT, ctrlc_handler);
  39. }